package way.scripts.classDoc.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Haozhiqiang  {2021/12/7 16:32}
 */
public class Table {

    private final String[] columns;
    private final List<List<String>> rows;

    public Table(String... columns) {
        this.columns = columns;
        this.rows = new ArrayList<>();
    }

    public void addRow(List<String> row) {
        if (row.size() > columns.length) {
            throw new IndexOutOfBoundsException();
        }
        this.rows.add(row);
    }

    public void addRow(String... row) {
        if (row.length > columns.length) {
            throw new IndexOutOfBoundsException();
        }
        this.rows.add(Arrays.asList(row));
    }

    public String[] getColumns() {
        return columns;
    }

    public List<List<String>> getRows() {
        return rows;
    }
}
